#include "power_app.h"
#include "gpio.h"

void power_init()
{
  GPIO_ConfigurePin(PW_ON_PORT, PW_ON_PIN, OUTPUT, PID_GPIO, false);       //power_on
  GPIO_ConfigurePin(COM_ON_PORT, COM_ON_PIN, OUTPUT, PID_GPIO, false);         //change
	if(get_power_volt()<ALARM_VOT){
		printf("voltage low %ld\n",get_power_volt());
		//beep_task(3,2);
		
		//led_task(2,2);
	}
}

void charge_on()
{
    CHARGE_ON();
}
void charge_off()
{
    CHARGE_OFF();

}

uint32_t get_adc_val(uint16_t channel)
{
    uint32_t adc_sample = 0;
    adc_init(GP_ADC_SE, 0, GP_ADC_ATTN3X);
    adc_enable_channel(channel);
    adc_sample = adc_get_sample();
    //printf("ADC: %ld\n", adc_sample);
    return adc_sample;

}

uint32_t get_power_volt()
{
    uint32_t voltage = 0;
    voltage = get_adc_val(ADC_CHANNELx);
    voltage = (3600 * voltage) / 1024;
    return voltage;
	
}

